﻿using System;
using System.ComponentModel;
using System.Text;

public class Common
{
    public static StringBuilder fillDescription = new StringBuilder();

    public static void Print(string text)
    {
        Console.WriteLine(text);
    }

    public static string InputArrayDescription(int[] array, string description)
    {
        StringBuilder addDescription = new StringBuilder();
        addDescription.Append(description);
        addDescription.Append("\nLength of array: ");
        addDescription.Append(array.Length + "\n");
        return Common.FillDescription(array, addDescription.ToString()) + "\n";
    }

    public static string InputArrayDescription(decimal[] array, string description)
    {
        StringBuilder addDescription = new StringBuilder();
        addDescription.Append(description);
        addDescription.Append("\nLength of array: ");
        addDescription.Append(array.Length + "\n");
        return Common.FillDescription(array, addDescription.ToString()) + "\n";
    }

    public static decimal[] InputArray(decimal[] array, string description)
    {
        StringBuilder addDescription = new StringBuilder();
        addDescription.Append(description);
        int arrayLength = Common.InputPositiveInteger(addDescription.Append("\nLength of array: ").ToString());
        array = new decimal[arrayLength];
        addDescription.Append(arrayLength + "\n");
        array = Common.FillArray(array, addDescription.ToString());
        return array;
    }

    public static int[] InputArray(int[] array, string description)
    {
        StringBuilder addDescription = new StringBuilder();
        addDescription.Append(description);
        int arrayLength = Common.InputPositiveInteger(addDescription.Append("\nLength of array: ").ToString());
        array = new int[arrayLength];
        addDescription.Append(arrayLength + "\n");
        array = Common.FillArray(array, addDescription.ToString());
        return array;
    }

    public static string FillDescription(decimal[] array, string description)
    {
        fillDescription.Clear();
        fillDescription.Append(description);
        for (int i = 0; i < array.Length; i++)
            fillDescription.Append("array[" + i + "] = " + array[i] + "\n");

        return fillDescription.ToString();
    }

    public static string FillDescription(int[] array, string description)
    {
        fillDescription.Clear();
        fillDescription.Append(description);
        for (int i = 0; i < array.Length; i++)
            fillDescription.Append("array[" + i + "] = " + array[i] + "\n");

        return fillDescription.ToString();
    }

    public static decimal[] FillArray(decimal[] array, string description)
    {
        fillDescription.Clear();
        fillDescription.Append(description);
        for (int i = 0; i < array.Length; i++)
        {
            do
            {
                Console.Clear();
                Console.Write(fillDescription + "array[{0}] = ", i);
                if (decimal.TryParse(Console.ReadLine(), out array[i]))
                {
                    fillDescription.Append("array[" + i + "] = " + array[i] + "\n");
                    break;
                }
            } while (true);
        }

        return array;
    }

    public static int[] FillArray(int[] array, string description)
    {
        fillDescription.Clear();
        fillDescription.Append(description);
        for (int i = 0; i < array.Length; i++)
        {
            do
            {
                Console.Clear();
                Console.Write(fillDescription + "array[{0}] = ", i);
                if (int.TryParse(Console.ReadLine(), out array[i]))
                {
                    fillDescription.Append("array[" + i + "] = " + array[i] + "\n");
                    break;
                }
            } while (true);
        }

        return array;
    }

    public static int InputInteger(string description)
    {
        int number;

        do
        {
            Console.Clear();
            Console.Write(description);
            if (int.TryParse(Console.ReadLine(), out number))
                return number;
        } while (true);
    }

    public static int InputPositiveInteger(string description)
    {
        int number;

        do
        {
            number = InputInteger(description);
        } while (number <= 0);

        return number;
    }

    public static int InputNonNegativeInteger(string description)
    {
        int number;

        do
        {
            number = InputInteger(description);
        } while (number < 0);

        return number;
    }

    public static decimal InputNonNegativeDecimal(string description)
    {
        decimal number;

        do
        {
            number = InputDecimal(description);
        } while (number < 0);

        return number;
    }

    public static decimal InputDecimal(string description)
    {
        decimal number;

        do
        {
            Console.Clear();
            Console.Write(description);
            if (decimal.TryParse(Console.ReadLine(), out number))
                return number;
        } while (true);
    }

    public static int GetMax(int m, int n)
    {
        if (m <= n)
            return n;
        else
            return m;
    }

    public static void Main()
    {

    }
}